package com.hbsx.why.ui.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hbsx.why.NormalMainActivity;
import com.hbsx.why.R;
import com.hbsx.why.TabMainActivity;
import com.hbsx.why.base.BaseFragment;
import com.hbsx.why.ui.activity.ActivityDetailActivity;
import com.hbsx.why.utils.PopWindowMine;
import com.hbsx.why.views.AllRoundImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MineFragment extends BaseFragment {
    public static TabMainActivity myTabActivity;
    private static String mTitle;
    private static String BUNDLE_flag = "BUNDLE_flag";
    @BindView(R.id.mine_headimg)
    AllRoundImageView mineHeadimg;
    @BindView(R.id.mine_name)
    TextView mineName;
    @BindView(R.id.mine_headimg1)
    AllRoundImageView mineHeadimg1;
    @BindView(R.id.mine_name1)
    TextView mineName1;
    @BindView(R.id.mine_jiangpai_logo)
    ImageView mineJiangpaiLogo;
    @BindView(R.id.mine_lv_logo)
    ImageView mineLvLogo;
    @BindView(R.id.pop_mine)
    View popMine;
    private int flag;

    public static NormalMainActivity myNormalMainActivity;

    @Override
    protected int getLayout() {
        return R.layout.ui_mine_fragment;
    }

    @Override
    protected void onInit() {
        Bundle arguments = getArguments();
        // LogUtils.logi("---MineFragment---flag="+flag);
        if (arguments != null) {
            flag = arguments.getInt(BUNDLE_flag);
        }
    }

    @Override
    public void fetchData() {
        //数据加载，每次进入此Fragment刷新
    }

    public static MineFragment newInstance() {
        MineFragment fragment = new MineFragment();
        return fragment;
    }

    public static MineFragment newInstance(String title, int flag) {
        MineFragment fragment = new MineFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(BUNDLE_flag, flag);
        mTitle = title;
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!ishowed) {
            ishowed = true;
        }
    }

    private PopWindowMine minepopWindow;
    private boolean ishowed = false;

    public void initPopWindow(View views) {
        minepopWindow = new PopWindowMine(getContext()) {
            @Override
            public int getLayoutManu() {
                return R.layout.layout_pop_mine;
            }

            @Override
            public void getView(View view) {
                view.findViewById(R.id.WX_share1).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        launch(ShareActivity.class);
                        minepopWindow.dismiss();
                    }
                });
                view.findViewById(R.id.WX_share2).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        launch(ShareActivity.class);
                        minepopWindow.dismiss();
                    }
                });
                view.findViewById(R.id.QQ_share1).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        launch(ShareActivity.class);
                        minepopWindow.dismiss();
                    }
                });
                view.findViewById(R.id.QQ_share2).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        launch(ShareActivity.class);
                        minepopWindow.dismiss();
                    }
                });
            }
        };
//        LogUtils.logi("----" + popWindow);
        minepopWindow.showAsDropDown();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @OnClick({R.id.mine_personal, R.id.mine_volunteer_click, R.id.mine_team_click, R.id.mine_suggest_click1, R.id.mine_set_click1, R.id.mine_coin1, R.id.mine_yaoqing_click, R.id.mine_pinglun_click, R.id.mine_sign, R.id.mine_sign1, R.id.mine_dianzan_click, R.id.mine_coin, R.id.mine_headimg, R.id.mine_yuyue_click, R.id.mine_yuyue_click1, R.id.mine_shoucang_click, R.id.mine_set_click, R.id.mine_suggest_click, R.id.mine_aboutus_click, R.id.mine_vision_click})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //签到
            case R.id.mine_sign:
                launch(SignActivity.class);
                break;
            case R.id.mine_sign1:
                launch(SignActivity.class);
                break;
            //积分
            case R.id.mine_coin:
                launch(CoinActivity.class);
                break;
            case R.id.mine_coin1:
                launch(CoinActivity.class);
                break;
            //头像个人资料
            case R.id.mine_headimg:
                launch(PersonalActivity.class);
                break;
            case R.id.mine_personal:
                launch(PersonalActivity.class);
                break;
            //预约
            case R.id.mine_yuyue_click:
                launch(YuYueActivity.class);
                break;
            case R.id.mine_yuyue_click1:
                launch(YuYueActivity.class);
                break;
            //收藏
            case R.id.mine_shoucang_click:
                launch(CollectActivity.class);
                break;
            //设置
            case R.id.mine_set_click:
                launch(SetActivity.class);
                break;
            case R.id.mine_set_click1:
                launch(SetActivity.class);
                break;
            //点赞
            case R.id.mine_dianzan_click:
                launch(DianZanActivity.class);
                break;
            //评论
            case R.id.mine_pinglun_click:
                launch(PingLunActivity.class);
                break;
            //邀请好友
            case R.id.mine_yaoqing_click:
                initPopWindow(popMine);
//                launch(ShareActivity.class, new Intent().putExtra("activity_id", "0").putExtra("activity_desc", "文化云").putExtra("flag", "0"));
                break;
            //意见反馈
            case R.id.mine_suggest_click:
                launch(SuggestActivity.class);
            case R.id.mine_suggest_click1:
                launch(SuggestActivity.class);
                break;
            //关于我们
            case R.id.mine_aboutus_click:
                launch(AboutUsActivity.class);
                break;
            //我的社团
            case R.id.mine_team_click:
                launch(TeamActivity.class);
                break;
            //志愿者
            case R.id.mine_volunteer_click:
                launch(VolunteerActivity.class);
                break;
            //版本
//            case R.id.mine_vision_click:
//                launch(ActivityCalendar.class);
//                break;
        }
    }
}
